package com.shuoyue.ycgk.views.dialog.file_dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.entity.NoticeFile;
import com.shuoyue.ycgk.ui.news.NoticeFileAdapter;

import java.util.List;


/**
 * 播放倍速选择Dialog
 * Created by Forty'7 on 2019/8/17
 */

public class FileDialog extends Dialog {
    private Context mContext;
    private RecyclerView mRecyclerView;
    private TextView tvClose;

    private NoticeFileAdapter mAdapter;

    public interface SelectCall {
        void select(NoticeFile speed);
    }

    public FileDialog(@NonNull Context context, List<NoticeFile> mDatas) {
        super(context, R.style.dialog);
        this.mContext = context;
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setWindowAnimations(R.style.ChooseStyle);
        setContentView(R.layout.dialog_speed);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        getWindow().setGravity(Gravity.BOTTOM);

        mRecyclerView = findViewById(R.id.recycler_view);
        tvClose = findViewById(R.id.tv_close);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        mAdapter = new NoticeFileAdapter(mDatas);
        mRecyclerView.setAdapter(mAdapter);

        mAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (call != null) {
                call.select(mAdapter.getItem(position));
            }
        });

        tvClose.setOnClickListener(v -> hide());


    }

    SelectCall call;

    public void addSelectCall(SelectCall call) {
        this.call = call;
    }
}
